package com.weetop.cfw.mine.adapter

import android.view.LayoutInflater
import android.view.View
import com.blankj.utilcode.util.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.coorchice.library.SuperTextView
import com.weetop.cfw.R
import com.weetop.cfw.bean.MyLeaseSaleInformationListBean
import com.weetop.cfw.constants.UrlConstants
import com.weetop.cfw.home_page.activity.PlantSalePublishActivity
import com.weetop.cfw.home_page.activity.PublishActivity
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import com.zhy.view.flowlayout.TagFlowLayout

class LeaseSaleInformationAdapter(layoutId:Int, dataList:List<MyLeaseSaleInformationListBean.DataBean>):BaseQuickAdapter<MyLeaseSaleInformationListBean.DataBean,BaseViewHolder>(layoutId,dataList) {


    override fun convert(helper: BaseViewHolder, item: MyLeaseSaleInformationListBean.DataBean?) {
       val textWorkshopImg = helper.getView<SuperTextView>(R.id.textWorkshopImg)
       val flowWorkshopDesc: TagFlowLayout = helper.getView(R.id.flowWorkshopDesc)
        helper.addOnClickListener(R.id.llDelete, R.id.llMotify,R.id.llTop,R.id.llRefresh)

        val tagList = ArrayList<String?>()
        if(item?.isalone?.trim() == "1"){
            tagList.add("独院")
        }else{

        }
        if(item?.haslift?.trim() == "1"){
            tagList.add("电梯")
        }else{

        }
        if(item?.floor?.trim() != ""){
            tagList.add("${item?.floor}层")
        }else{

        }
        flowWorkshopDesc.adapter = object: TagAdapter<String>(tagList){
            override fun getView(parent: FlowLayout?, position: Int, t: String?): View {
                val textItemWorkshopDescFlowLayoutView = LayoutInflater.from(mContext).inflate(R.layout.layout_item_workshop_desc_flow,parent,false)
                val textItemWorkshopDesc = textItemWorkshopDescFlowLayoutView.findViewById<SuperTextView>(R.id.textItemWorkshopDesc)
                textItemWorkshopDesc.text = tagList[position]
                return textItemWorkshopDescFlowLayoutView
            }
        }
        LogUtils.eTag("textWorkshopImg",item?.imgurl)
        textWorkshopImg.setUrlImage("${UrlConstants.baseUrl}${item?.imgurl}")
        LogUtils.eTag("LeaseSaleInformationItemImage","${UrlConstants.baseUrl}${item?.imgurl}")
        helper.setText(R.id.textWorkshopName,item?.title).setText(R.id.textWorkshopAddress,"地址：${item?.areaname} ${item?.address}")
            .setText(R.id.textWorkshopArea,"面积：${item?.totalarea}㎡")
        helper.setOnClickListener(R.id.textEditInfoLabel) {
            if(item != null){
                if(item.intid == 1 && item.typeid == "1201"){//厂房出租
                    PublishActivity.startPublishActivity(mContext, isEditPublishInfo = true, isWorkshopOrWareHouse = true,infoid = item.infoid)
                }else if(item.intid == 2 && item.typename == "1201"){//厂房出售
                    PlantSalePublishActivity.startPlantSalePublishActivity(mContext,editPublish = true,isWorkShopOrWarehouse = true,infoid = item.infoid)
                }else if(item.intid == 1 && item.typeid == "1202"){//仓库出租
                    PublishActivity.startPublishActivity(mContext, isEditPublishInfo = true, isWorkshopOrWareHouse = false,infoid = item.infoid)
                }else if(item.intid == 2 && item.typeid == "1202"){//仓库出售
                    PlantSalePublishActivity.startPlantSalePublishActivity(mContext,editPublish = true,isWorkShopOrWarehouse = false,infoid = item.infoid)
                }
            }
        }

    }
}